<template>
	<view class="fui-wrap">
		<fui-sticky>
			<view style="background-color: #fff;">
				<fui-segmented-control @click="changeSegmented" :current="current" color="#000" activeColor="#0a8cdd" type="text" :values="segmented"></fui-segmented-control>
			</view>
		</fui-sticky>
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index">
				<view class="item" v-if="current===0">
					<view class="line">
						<fui-text text="操作时间：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.createtime" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="管理员：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.admin.nickname" color="black" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text text="操作：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.message" color="black" :size="28"></fui-text>
					</view>
				</view>
				<view class="item" v-if="current===1 && rules_type=='monthly'">
					<view class="line">
						<fui-text text="充值时间：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.createtime" color="black" :size="28"></fui-text>
					</view>
					<view class="line-between">
						<view class="one">
							<fui-text text="充值金额：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="'￥'+parseNumber(item.money)" color="black" :size="28"></fui-text>
						</view>
						<view class="one">
							<fui-text text="支付方式：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="item.payunion.pay_type_text" color="black" :size="28"></fui-text>
						</view>
					</view>
					<view class="line-between">
						<view class="one">
							<fui-text text="开始时间：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="formatDate(item.starttime)" color="black" :size="28"></fui-text>
						</view>
						<view class="one">
							<fui-text text="结束时间：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="formatDate(item.endtime)" color="black" :size="28"></fui-text>
						</view>
					</view>
				</view>
				<view class="item" v-if="current===1 && rules_type=='stored'">
					<view class="line">
						<fui-text text="充值时间：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.createtime" color="black" :size="28"></fui-text>
					</view>
					<view class="line-between">
						<view class="one one-40">
							<fui-text text="充值金额：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="'￥'+parseNumber(item.change)" color="black" :size="28"></fui-text>
						</view>
						<view class="one one-60">
							<fui-text text="支付方式：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="item.payunion.pay_type_text" color="black" :size="28"></fui-text>
						</view>
					</view>
					<view class="line-between">
						<view class="one one-40">
							<fui-text text="初始金额：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="'￥'+parseNumber(item.before)" color="black" :size="28"></fui-text>
						</view>
						<view class="one one-60">
							<fui-text text="充后金额：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="'￥'+parseNumber(item.after)"color="black" :size="28"></fui-text>
						</view>
					</view>
				</view>
				<view class="item" v-if="current===2">
					<view class="line">
						<fui-text text="变动时间：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<fui-text :text="item.createtime" color="black" :size="28"></fui-text>
					</view>
					<view class="line-between">
						<view class="one one-40">
							<fui-text text="变动金额：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="'￥'+parseNumber(item.change)" color="black" :size="28"></fui-text>
						</view>
						<view class="one one-60">
							<fui-text text="交易类型：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="item.log_type_txt" color="black" :size="28"></fui-text>
						</view>
					</view>
					<view class="line-between">
						<view class="one one-40">
							<fui-text text="交易前：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="'￥'+parseNumber(item.before)" color="black" :size="28"></fui-text>
						</view>
						<view class="one one-60">
							<fui-text text="交易后：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
							<fui-text :text="'￥'+parseNumber(item.after)"color="black" :size="28"></fui-text>
						</view>
					</view>
					<view class="line" style="height: auto;align-items: flex-start;margin-top: 10rpx;">
						<fui-text text="备注：" color="#afafaf" :size="28" align="right" block style="width: 140rpx;"></fui-text>
						<view style="width: 80%;">
							<fui-text :text="item.remark" color="black" :size="28"></fui-text>
						</view>
					</view>
				</view>
			</fui-list-cell>
		</fui-list>
		<filter :param="param" @confirm="doSubmit"></filter>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {parseNumber,formatDate} from '@/utils/util.js'
	import filter from '@/components/common/filter.vue';
	export default {
		components:{
			filter:filter
		},
		data() {
			return {
				baseUrl:baseUrl,
				segmented:['操作记录','充值记录','余额流水'],
				rules_type:'',
				cars_id:'',
				current:0,
				list:[],
				page:1,
				endData:false,
				param:{
					starttime:'',
					endtime:''
				}
			}
		},
		onLoad(e) {
			this.cars_id=e.cars_id;
			this.rules_type=e.rules_type;
			this.getList();
		},
		onShow() {
			let refresh=uni.getStorageSync('refresh') || '';
			if(refresh){
				this.list=[];
				this.page=1;
				this.endData=false;
				uni.setStorageSync('refresh','');
				this.getList();
			}
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			parseNumber,
			formatDate:function(i){
				return formatDate(new Date(i*1000));
			},
			changeSegmented:function(e){
				this.current=e.index;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			getList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				let type=['logs','recharge','balance'];
				this.$get('parking/cars/log',{
					...this.param,
					type:type[this.current],
					rules_type:this.rules_type,
					cars_id:this.cars_id,
					page:this.page
				},true).then(res=>{
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.item{
	display: flex;
	flex-wrap: wrap;
	.line{
		display: flex;
		align-items: center;
		width:100%;
		height: 70rpx;	
	}
	.line-between{
		display: flex;
		align-items: center;
		width:100%;
		height: 70rpx;
		.one{
			display: flex;
			align-items: center;
			width: 50%;
		}
		.one-40{
			width: 40%;
		}
		.one-60{
			width: 60%;
		}
	}
}
</style>